package com.project.Service.impl;


import com.project.Bean.RoomFacility;
import com.project.Service.IRoomFacilityService;
import com.project.mapper.IClassRoomMapper;
import com.project.mapper.IRoomFacilityMapper;
import com.project.mapper.IRoomMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/***
 * 房间设施实现类
 */
public class IRoomFacilityServiceImpl extends BaseService implements IRoomFacilityService {

    @Override
    public void addInfo(RoomFacility roomFacility, int roomId) {
        SqlSession session = this.getSession();
        IRoomFacilityMapper mapper = session.getMapper(IRoomFacilityMapper.class);
        IRoomMapper mapper1 = session.getMapper(IRoomMapper.class);
        mapper.addInfo(roomFacility);
        mapper1.updateSta(roomId,"设施损坏");
        session.commit();
        session.close();
    }

    @Override
    public void dispose(int id, int roomId) {
        SqlSession session = this.getSession();
        IRoomFacilityMapper mapper = session.getMapper(IRoomFacilityMapper.class);
        IRoomMapper mapper1 = session.getMapper(IRoomMapper.class);
        mapper.updateFacility(id,"已解决");
        if(mapper.countByRoom(roomId,"未解决") == 0){
            mapper1.updateSta(roomId,"正常");
        }
        session.commit();
        session.close();
    }

    @Override
    public List<RoomFacility> findAll(int roomId) {
        SqlSession session = this.getSession();
        IRoomFacilityMapper mapper = session.getMapper(IRoomFacilityMapper.class);
        List<RoomFacility> roomFacilities = mapper.findAll(roomId);

        session.close();
        return roomFacilities;
    }
}
